package 北京建筑大学;

import com.alibaba.excel.EasyExcel;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class BJju {
    public static void main(String[] args) throws IOException {
        BJjuBean bJjuBean = null;
        List<BJjuBean> bJjuBeans = new ArrayList<>();
        Connection connect = Jsoup.connect("https://dxxy.bucea.edu.cn/szdw/js1/index.htm");
        Document post = connect.post();
        for (Element flei : post.getElementsByClass("flei")) {
            for (Element element : flei.getElementsByTag("ul")) {
                for (Element li : element.getElementsByTag("li")) {
                    bJjuBean = new BJjuBean();
                    String text = li.text();
                    bJjuBean.setT_name(text);
                    String attr = li.getElementsByTag("a").get(0).attr("href");
//                    System.out.println(attr);
                    Connection connect1 = Jsoup.connect("https://dxxy.bucea.edu.cn/szdw/js1/" + attr);
                    Document post1 = connect1.post();
                    for (Element title : post1.getElementsByTag("ul")) {
                        bJjuBean.setInfo(title.text());
//                        System.out.println(title.text());
                        bJjuBeans.add(bJjuBean);
                    }

                }

            }

        }
        EasyExcel.write("src/BJju.xlsx", BJjuBean.class).sheet("user").doWrite(bJjuBeans);

    }
}
